import os

import pandas as pd


def merged_file(folder):
    files = [file for file in os.listdir(folder) if file.endswith('.csv')]
    data_frames = []

    for file in files:
        file_path = os.path.join(folder, file)
        try:
            # 使用dtype指定第85列为字符串
            df = pd.read_csv(file_path, dtype={85: str}, low_memory=False)
            data_frames.append(df)
        except Exception as e:
            print(f"Error reading {file}: {e}")

    pd.concat(data_frames, ignore_index=True).to_csv(os.path.join(folder, 'merged', 'all_data.csv'), index=False)


if __name__ == '__main__':
    merged_file('.')
